﻿using System;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.ScheduleJob.SPI;

namespace T.FAS.Runtime.ScheduleJob.Dao
{
    public class ScheduleJobRTPLogic
    {
     
        public void AddScheduleJobInstance(ScheduleJobInstanceStore instance)
        {
            ScheduleJobInstanceDao dao = new ScheduleJobInstanceDao();
            instance.StartTime = DateTime.Now;
            instance.EndTime = DateTime.Now;
            dao.Add(new List<object> { instance });
        }
        public bool IsExistsInstance(string instanceID)
        {
            ScheduleJobInstanceDao dao = new ScheduleJobInstanceDao();
            return dao.IsExistsInstance(instanceID);
        }

        public List<ScheduleJobInstanceStore> GetScheduleJobInstances(UserDefineQueryFilter filter)
        {
            ScheduleJobInstanceDao dao = new ScheduleJobInstanceDao();
            var list = dao.GetScheduleJobInstances(filter);
            return list;
        }
        public List<ScheduleJobInstanceStore> GetAllToBeExecutedScheduleJobInstances()
        {
            ScheduleJobInstanceDao dao = new ScheduleJobInstanceDao();
            var list = dao.GetAllToBeExecutedScheduleJobInstances();
            return list;
        }
        public List<ScheduleJobInstanceStore> GetAllNeedAutoStartScheduleJobInstances()
        {
            ScheduleJobInstanceDao dao = new ScheduleJobInstanceDao();
            var list = dao.GetAllNeedAutoStartScheduleJobInstances();
            return list;
        }
        public ScheduleJobInstanceStore GetScheduleJobInstanceByInstanceID(string instanceID)
        {
            ScheduleJobInstanceDao dao = new ScheduleJobInstanceDao();
            var data = dao.GetScheduleJobInstanceByInstanceID(instanceID);
            return data;
        }
        public void UpdateScheduleJobInstanceState(string instanceID, ScheduleJobStateNoticeData data)
        {
            ScheduleJobInstanceDao dao = new ScheduleJobInstanceDao();
            dao.UpdateScheduleJobInstanceState(instanceID, data);
        }
        public List<ScheduleJobInstanceStore> GetReadyToFireScheduleJobInstances(UserDefineQueryFilter filter)
        {
            ScheduleJobInstanceDao dao = new ScheduleJobInstanceDao();
            var storeLists = dao.GetScheduleJobInstances(filter);
            return storeLists;
        }
    }
}
